package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28779
 * Date: 2023-04-02
 * Time: 9:37
 */
/*class MyArray{
    public Object[] objects = new Object[10];

    public Object getPos(int pos){
        return objects[pos];
    }
    public void setVal(int pos, Object val){
        objects[pos] = val;

    }
}*/
class MyArray<T>{
    public Object[] objects = new Object[10];  //这样写也是不好的

    public T getPos(int pos){
        return (T)objects[pos];
    }
    public void setVal(int pos, T val){
        objects[pos] = val;
    }
    public Object[] getArray(){
        return objects;
    }
}
public class Test1 {
    public static void main(String[] args) {
        MyArray<Integer> myArray = new MyArray<Integer>();
        myArray.setVal(0,48);
        myArray.setVal(1,10);
        int val = myArray.getPos(1);
        System.out.println(val);
        System.out.println("==================");
        MyArray<String> myArray1 = new MyArray<>();
        myArray1.setVal(0,"张兆涵");
        String val1 = myArray1.getPos(0);
        System.out.println(val1);

    }
}
